/*******************************************************************************
 * Copyright (c) 2003, 2010 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.karelun.whiteboard.gef;

import org.eclipse.core.runtime.Assert;
import org.eclipse.draw2d.geometry.PrecisionRectangle;

public class CompoundSnapToHelper extends SnapToHelper {

	private SnapToHelper[] delegates;

	public CompoundSnapToHelper(SnapToHelper delegates[]) {
		Assert.isTrue(delegates.length != 0);
		this.delegates = delegates;
	}

	protected SnapToHelper[] getDelegates() {
		return delegates;
	}

	public int snapRectangle(Request request, int snapOrientation,
			PrecisionRectangle baseRect, PrecisionRectangle result) {
		for (int i = 0; i < getDelegates().length && snapOrientation != NONE; i++)
			snapOrientation = getDelegates()[i].snapRectangle(request,
					snapOrientation, baseRect, result);
		return snapOrientation;
	}

}
